<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <html>
        <head>
            <title></title>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <script src="__PUBLIC__/jquery-1.7.2.min.js"></script>
            <css file='__PUBLIC__/Uploadify/uploadify.css'/>
            <script src="__PUBLIC__/uploadify/jquery.uploadify-3.1.min.js"></script>
            <link href="__PUBLIC__/admin/css/category.css" rel="stylesheet" type="text/css"/>  
        <script>
            
            var attrurl="{:U('getAttr')}";
            $(function(){
                
                $('input[type="checkbox"]').live('click',function(){
//                    alert($(this).parent().html());
//alert($('input[type="checkbox"]').attr('checked'));
                    if($('input[type="checkbox"]').attr('checked')!='checked'){
                        $(this).next('span').remove();
                    }else{
                        $(this).after('<span>&nbsp;价格:<input style="width:50px;" type="text" name="price[]"></span>');
                    }
                    
                });
                
                
                $('select[name="cid"]').change(function(){
                    if($(':selected',this).attr('pid')==0){
                        $('.msgc').html('<font color="red">顶级分类不可添加商品</font>');
                        $('select[name="cid"] option').eq(0).attr('selected','selected');
                    }else{
                        $('.msgc').html('');
                        var type_id= $(':selected', this).attr('type_id');
                        $.get(attrurl,{'type_id':type_id},function(data){
                            var attr = '';	//属性节点字符串
                            var spec = '';	//规格节点字符串
                            $.each(data,function(k,v){
                                if(v.flag==1){  
                                    attr += '<tr><th width="10%">'+v.attr_name+'</th><td>';
                                    var option = v.attr_choose.split(',');
                                    for (var i=0; i < option.length; i++) {
                                            attr += '<input type="radio" name="pro[]" value="'+ v.pro_id  + option[i] + '"/>&nbsp;' + option[i] + '&nbsp;&nbsp;';
                                             
                                    }
                                    //属性选项为空时提供手写框
//                                    attr += '&nbsp;&nbsp;&nbsp;手动填写&nbsp;<input type="text" name="'+v.pro_id+'"/>';
                              
                                    attr += '</td></tr>';

                                }else{
                                    spec += '<tr><th width="10%">' + v.attr_name + '</th>';
                                    spec += '<td><select name="pro_id[]">';
                                    spec += '<option value="">请选择</option>';
                                    var option =v.attr_choose.split(',');
                                    for (var i=0; i < option.length; i++) {
                                            spec += '<option value="'+ v.pro_id + option[i] + '">' + option[i] + '</option>';
                                    }
                                    spec += '</select>';
                                    spec += '价格：<input type="text" name="price[]"/>';
                                    spec += '数量：<input type="text" name="count[]"/>';
                                    spec += '<span class="addSpec" style="cursor:pointer;">[+]添加一项</span></td></tr>';
                                }
                            })
                            $('#attr').html('').append(attr);
                             $('#spec').html('').append(spec);
                        },'json');
                    }
                });
                //添加一个规格
	$('.addSpec').live('click', function () {
		var obj = $(this).parents('tr');
		var obj2 = obj.clone(obj);
              
		$('#spec tbody').append(obj2);
	});
            })
        </script>
            <style>
                table th{width:20%;}
                table td{width:50%;}
            </style>
    </head>
    <body>
        <div class='content'>
                <div class='t'>
			<h3>添加商品</h3>
		</div>
            <form action="{:U('add')}" method="post" enctype='multipart/form-data'>
                        <table>
                           
                            <tr>
                                <th width="10%">商品分类</th>
                                <td width="50%">
                                    <select name="cid">
                                        <option>--商品分类--</option>
                                        <foreach name='cate' item="c">
                                            <option value="{$c.cid}" pid="{$c.pid}" type_id="{$c.type_id}">{$c.html}{$c.name}</option>
                                        </foreach>
                                    </select><span class='msgc'></span>
                                </td>
                            </tr>
                            <tr>
                                <th>商品名称</th>
                                <td><input type="text" name='name'/></td>
                            </tr>
                            <tr>
                                <th>货号</th>
                                <td><input type="text" name='num'/><span>不输入，系统将生成默认编号</span></td>
                            </tr>
                            <tr>
                                <th>商城价</th>
                                <td><input type="text" name='zen_price'/></td>
                            </tr>
                            <tr>
                                <th>市场价</th>
                                <td><input type="text" name='market_price'/></td>
                            </tr>
                            <tr>
                                <th>单位</th>
                                <td><input type="text" name='unit'/></td>
                            </tr>
                            <tr>
                                <th>点击数</th>
                                <td><input type="text" name='click'/></td>
                            </tr>
                            
                        </table>
                <table id='attr'>
  
                </table>
                <table id='spec'>
  
                </table>
                    <div>
                        <tr>
                                <td colspan="2" width="45%" align='right'><input type="submit" class="bt1" value="添 加"/></td>
                            </tr>
                    </div>

            </form>
        </div>
    </body>
</html>